﻿using HealthcareSystem.API.Read.Application.Command.ChronicSign;
using HealthcareSystem.Domain;
using MediatR;
using Microsoft.EntityFrameworkCore;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Read.Application.CommandHandel.ChronicSignHandel
{
    public class ShowCSignOneCommadHandel : IRequestHandler<ShowCSignOneCommad, ApiResult<List<Record>>>
    {
        private readonly IBaseRepository<Record> recordRepository;

        public ShowCSignOneCommadHandel(IBaseRepository<Record> recordRepository)
        {
            this.recordRepository = recordRepository;
        }
        public async Task<ApiResult<List<Record>>> Handle(ShowCSignOneCommad request, CancellationToken cancellationToken)
        {
            ApiResult<List<Record>> result=new ApiResult<List<Record>>();
            result.Code=ResultCode.Success;
            result.Message = "成功";
            var list = await(from a in recordRepository.GetAll()
                             where a.RecordName == request.RecordName
                             select a).ToListAsync(cancellationToken);

        
            result.Data = list;
            return await Task.FromResult(result);
        }
    }
}
